package com.dongdongsongcan.app.activity;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.ViewFlipper;

import com.dongdongsongcan.app.R;
import com.dongdongsongcan.app.fragment.LoginAccountFragment;
import com.dongdongsongcan.app.fragment.LoginPhoneFragment;
import com.su.dolphin.utils.mgr.DpActivityManager;
import com.su.dolphin.utils.mgr.DpFragmentManager;
import com.su.dolphin.utils.ui.DpTitleBar.OnRightButtonClickListener;
import com.su.dolphin.view.activity.BaseActivity;

public class LoginActivity extends BaseActivity {

    public static void startFrom(Context context) {
        DpActivityManager.i().startActivity(context, LoginActivity.class);
       // ((Activity) context).finish();
    }

    private ViewFlipper mLogin_viewflipper_tab;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_login);
        setTitle("登陆");
        getDpTitleBar().setRightButtonText("注册新用户",
                new OnRightButtonClickListener() {

                    @Override
                    public void onRightBtnClick(View button) {
                        RegisterActivity.startFrom(LoginActivity.this);
                    }
                }, null, null);
    }

    @Override
    public void initView() {

        mLogin_viewflipper_tab = (ViewFlipper) findViewById(R.id.login_viewflipper_tab);
        DpFragmentManager.i().replaceFragment(this, R.id.login_tab_phone,
                LoginPhoneFragment.class);
        DpFragmentManager.i().replaceFragment(this, R.id.login_tab_account,
                LoginAccountFragment.class);

    }

    @Override
    public void setListener() {
        findViewById(R.id.login_tab_btn1).setOnClickListener(this);
        findViewById(R.id.login_tab_btn2).setOnClickListener(this);
    }

    @Override
    public void initData() {

    }

    @Override
    public void onClick(View arg0) {
        switch (arg0.getId()) {
            case R.id.login_tab_btn1:
                mLogin_viewflipper_tab.setDisplayedChild(0);
                break;
            case R.id.login_tab_btn2:
                mLogin_viewflipper_tab.setDisplayedChild(1);
                break;
            default:
                break;
        }
    }
}
